package com.ruoyi.productcategories.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.productcategories.domain.Productcategories;
import com.ruoyi.productcategories.service.IProductcategoriesService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 商品分类关联Controller
 * 
 * @author sqlstudent
 * @date 2025-06-24
 */
@RestController
@RequestMapping("/productcategories/productcategories")
public class ProductcategoriesController extends BaseController
{
    @Autowired
    private IProductcategoriesService productcategoriesService;

    /**
     * 查询商品分类关联列表
     */
    @PreAuthorize("@ss.hasPermi('cart:cart:list')")
    @GetMapping("/list")
    public TableDataInfo list(Productcategories productcategories)
    {
        startPage();
        List<Productcategories> list = productcategoriesService.selectProductcategoriesList(productcategories);
        return getDataTable(list);
    }

    /**
     * 导出商品分类关联列表
     */
    @PreAuthorize("@ss.hasPermi('cart:cart:list')")
    @Log(title = "商品分类关联", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Productcategories productcategories)
    {
        List<Productcategories> list = productcategoriesService.selectProductcategoriesList(productcategories);
        ExcelUtil<Productcategories> util = new ExcelUtil<Productcategories>(Productcategories.class);
        util.exportExcel(response, list, "商品分类关联数据");
    }

    /**
     * 获取商品分类关联详细信息
     */
    @PreAuthorize("@ss.hasPermi('cart:cart:list')")
    @GetMapping(value = "/{productId}")
    public AjaxResult getInfo(@PathVariable("productId") Long productId)
    {
        return success(productcategoriesService.selectProductcategoriesByProductId(productId));
    }

    /**
     * 新增商品分类关联
     */
    @PreAuthorize("@ss.hasPermi('cart:cart:list')")
    @Log(title = "商品分类关联", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Productcategories productcategories)
    {
        return toAjax(productcategoriesService.insertProductcategories(productcategories));
    }

    /**
     * 修改商品分类关联
     */
    @PreAuthorize("@ss.hasPermi('cart:cart:list')")
    @Log(title = "商品分类关联", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Productcategories productcategories)
    {
        return toAjax(productcategoriesService.updateProductcategories(productcategories));
    }

    /**
     * 删除商品分类关联
     */
    @PreAuthorize("@ss.hasPermi('cart:cart:list')")
    @Log(title = "商品分类关联", businessType = BusinessType.DELETE)
	@DeleteMapping("/{productIds}")
    public AjaxResult remove(@PathVariable Long[] productIds)
    {
        return toAjax(productcategoriesService.deleteProductcategoriesByProductIds(productIds));
    }
}
